<?php
/**
 * AdminBaseController
 *
 * @author
 * @version
 */

class AdminBaseController extends Zend_Controller_Action
{
	protected $_user;
	protected $_redirector;
	protected $_languages_path;
	protected $_languages;
	
	
	public function init()
	{
		$this->_redirector = new Zend_Controller_Action_Helper_Redirector();
		
		$this->view->baseUrl = $this->_request->getBaseUrl();
		
		$locale = Zend_Registry::get('locale');
		
		$this->_languages_path = BP . '/application/languages/' . $locale->getLanguage() . '/';
		
		$this->_languages = new Zend_Translate_Adapter_Csv( $this->_languages_path . 'admin.csv', $locale);
		$this->view->languages = $this->_languages;
		
		/**
		 * 判断用户是否登陆
		 */
		$this->_user = Zend_Auth::getInstance()->getIdentity();
		
		if ($this->_user === NULL && $this->_request->getActionName() <> 'login')
		{
			$this->_redirector->gotoSimple('login', 'index', 'admin');
		}
		
		$this->view->user = $this->_user;
		
		$this->menuHandler();
		
	}
	
	/**
	 * menuHandler
	 *
	 * @access private
	 * @return void
	 */
	private function menuHandler()
	{
		$adminMenu = new Zend_Config_Xml(BP . '/config/adminmenu.xml');
		$this->view->adminMenuArray = $adminMenu->toArray();
	}
}
?>